package com.dfbz.service.impl;

import com.dfbz.dao.UserDao;
import com.dfbz.pojo.PageEntity;
import com.dfbz.model.User;
import com.dfbz.service.UserService;
import com.dfbz.utils.PageUtil;

import java.util.ArrayList;
import java.util.List;

public class UserServiceImpl implements UserService {
    UserDao userDao=new UserDao();
    @Override
    public User findById(Integer id) {
        return userDao.findByid(id);
    }

    @Override
    public User findByName(String name) {
        return userDao.findByName(name);
    }

    @Override
    public User findByEmail(String email) {
        return userDao.findByEmail(email);
    }

    @Override
    public ArrayList<User> findList() {
        return userDao.findList();
    }

    @Override
    public List<User> findUsers() {
        return userDao.findUsers();
    }

    @Override
    public void register(User user) {
        userDao.register(user);
    }

    @Override
    public void save(User user) {
        userDao.save(user);
    }

    @Override
    public void deleteById(Integer id) {
        userDao.deleteById(id);
    }

    @Override
    public void update(User user) {
        userDao.update(user);
    }

    @Override
    public PageEntity<User> findPage(Integer currPage, String realName) {
        PageEntity<User> pageEntity = new PageEntity<>();
        List<User> pageData = userDao.findPage(realName, (currPage-1)*pageEntity.getPageSize(), pageEntity.getPageSize());
        Integer totalCount=userDao.countByRealName(realName);
        return PageUtil.getPageEntity(pageEntity,currPage,pageData,totalCount);
    }

    @Override
    public void updateLoginTime(User user) {
        userDao.updateLoginTime(user);
    }

    @Override
    public void updateImg(Integer id, String path) {
        User user=new User();
        user.setId(id);
        user.setPic(path);
        userDao.update(user);
    }

    @Override
    public void updateLook(Integer uId) {
        userDao.updateLook(uId);
    }

    @Override
    public PageEntity<User> findfocusAll(Integer currPage,Integer id) {
        PageEntity<User> pageEntity = new PageEntity<>();
        List<User> pageData = userDao.findfocusAll(id, (currPage - 1) * pageEntity.getPageSize(), pageEntity.getPageSize());
        Integer totalCount = userDao.countByfocusAll(id);
        return PageUtil.getPageEntity(pageEntity,currPage,pageData,totalCount);
    }
}
